package com.dayaokeji.rhythmschoolstudent.client.home.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.home.data.bean.ComponentBean;

import java.util.List;

/**
 * ********************************************************************
 * *  Created by Zeno on 2018/8/17
 * ********************************************************************
 * *  version 1.0
 * ********************************************************************
 * *  Copyright (C) dayaokeji.com 2018 -- 2020 All rights reserved.
 * ********************************************************************
 * *
 * ********************************************************************
 */
public class FunctionComponentAdapter extends BaseAdapter {

    private List<ComponentBean> componentBeans;

    public FunctionComponentAdapter(List<ComponentBean> componentBeans) {
        this.componentBeans = componentBeans;
    }

    @Override
    public int getCount() {
        return componentBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return componentBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ComponentBean componentBean = componentBeans.get(position);
        ComponentHolder holder;
        if (convertView == null) {
            holder = new ComponentHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_component, parent,false);
            holder.ivCover = convertView.findViewById(R.id.iv_cover);
            holder.tvTitle = convertView.findViewById(R.id.tv_title);
            convertView.setTag(holder);
        }else{
            holder = (ComponentHolder) convertView.getTag();
        }
        if (componentBean.getIconResId()  != -1) {
            holder.ivCover.setImageResource(componentBean.getIconResId());
            holder.tvTitle.setText(componentBean.getNameStr());
        }

        return convertView;
    }


    static class ComponentHolder{
         ImageView ivCover;
         TextView tvTitle;
    }
}
